<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机轮播图点击切换</title>
    <style>
        * {
            box-sizing:border-box
        }
        .one {
            width: 500px;
            height: 400px;
            /* border: 10px solid red; */
            /* overflow: hidden; */
        }
        .onebody {
            width: 100%;
            height: 320px;
            /* border: 1px solid red; */
        }
        .onebody img {
            width: 100%;
            height: 320px;
            display: block;
        }
        .onefoot {
            height: 80px;
            background-color: rgb(100, 67, 68);
            padding: 1px 0 0 0;
            position: relative;
            padding-left: 50px;
        }
        .onefoot_toggle {
            position: absolute;
            right: 0;
            top: 10px;
            display: flex;

        }
        .onefoot_toggle button {
            margin-right: 11px;
            width: 30px;
            border: none;  
            background:rgba(255, 255, 255, 0.1);
            color: white;
            border-radius: 5px;
            cursor: pointer;
            margin-top: 17px;

        }
        .onefoot_toggle button:hover {
            background: rgba(255, 255, 255, 0.2);
        }
        .onefoot p {
            margin-top: 20px;
            color: white;
            font-size: 18px;

        }
        .onefoot_indicator {
            display: flex;
            margin-top: -15px;
            padding: 0;
            list-style: none;
            align-items: center;
            /* border: 1px solid red; */
        }
        
        .onefoot_indicator li {
            display: flex;
            width: 8px;
            height: 8px;
            margin: 4px;
            border-radius: 50%;
            background: white;
            opacity: 0.4;
            cursor: pointer;
        }
        .onefoot_indicator li.active {
            width: 12px;
            height: 12px;
            opacity: 1;
        }
    </style>
</head>
<body>
    <div class="one">
        <div class="onebody">
            <img src="./背景图片/2.jpg">    
        </div>
        <div class="onefoot">
            <p></p>
            <ul class="onefoot_indicator"> 
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
           
            
            <div class="onefoot_toggle">
                <button class="prev">&lt;</button>
                <button class="next">&gt;</button>
            </div>
        </div>
    </div>
    <script>
        const onedata = [
            { url:'./背景图片/1.jpg',title:'这是什么？',color:'rgb(20,30,58)'},
            { url:'./背景图片/2.jpg',title:'不知道啊？',color:'rgb(20,30,58)'},
            { url:'./背景图片/4.jpg',title:'回家睡觉？',color:'rgb(20,30,58)'},
            { url:'./背景图片/3.jpg',title:'出去锻炼？',color:'rgb(20,30,58)'},
        ]
        const random=Math.floor(Math.random()*onedata.length)
        const img=document.querySelector(".onebody img")
        // console.log(img);
        img.src=onedata[random].url
        const p=document.querySelector(".onefoot p")
        p.innerHTML=onedata[random].title
        const foot=document.querySelector(".onefoot")
        foot.style.backgroundColor=onedata[random].color
        const li=document.querySelector(`.onefoot_indicator li:nth-child(${random+1})`)
        li.classList.add("active")
    </script>
</body>
</html>